package soap.latherqq.core.manage;



import iqq.im.QQActionListener;
import iqq.im.QQClient;
import iqq.im.event.QQActionEvent;
import iqq.im.event.QQActionFuture;

import org.apache.log4j.Logger;

/**
 * 服务管理，负责后台的交互
 * @author soap
 *
 */

public class ServiceManage {

	private static final Logger log = Logger.getLogger(ServiceManage.class);
	private static ServiceManage self = null;

	public static synchronized ServiceManage self() {
		if (self == null) {
			self = new ServiceManage();
		}
		return self;
	}

	private QQClient client;
	private QQActionFuture loginFuture;

	public QQClient getClient() {
		return client;
	}

	private ServiceManage() {

	}

	public void init(){

	}

	public void destroy(){
		if (client != null && client.isOnline()) {
			client.logout(new QQActionListener() {
				@Override
				public void onActionEvent(QQActionEvent event) {
					switch (event.getType()) {
					case EVT_OK:
						log.debug("登出成功");
						break;
					case EVT_ERROR:
						log.debug("登出失败");
						break;
					}
					client.destroy();
					System.exit(0);
				}
			});
		}
	}
	public void cancelLogin(){
		log.debug("取消登录");
	}
	public void login(String username, String password) {
		
	}

}
